package com.gujh.orm;


import cn.org.atool.fluent.mybatis.spring.SqlMapperFactory;
import com.gujh.orm.dao.impl.HelloWorldDaoImpl;
import com.gujh.orm.dao.intf.HelloWorldDao;
import com.gujh.orm.entity.HelloWorldEntity;
import com.gujh.orm.mapper.HelloWorldMapper;
import com.gujh.orm.wrapper.HelloWorldQuery;
import org.apache.commons.dbcp2.BasicDataSource;
import org.apache.ibatis.session.SqlSession;

import javax.sql.DataSource;

public class Test {

    public static void main(String[] args) {
        SqlMapperFactory factory = new SqlMapperFactory(dataSource(), HelloWorldMapper.class);
        HelloWorldQuery query = HelloWorldQuery.defaultQuery();
        HelloWorldDao helloWorldDao = new HelloWorldDaoImpl();
        HelloWorldEntity helloWorldEntity = new HelloWorldEntity();
        helloWorldEntity.setSayHello("ddd");
        helloWorldEntity.setYourName("bbb");
        factory.execute(HelloWorldMapper.class, mapper -> {
            Object save = mapper.save(helloWorldEntity);
            System.out.println(save);
        });
    }

    private static DataSource dataSource() {
        String url = "jdbc:mysql://101.35.187.114:3306/test?useUnicode=true&characterEncoding=utf8";
        String driver = "com.mysql.cj.jdbc.Driver";
        String username = "root";
        String password = "jiahe0528";
        BasicDataSource dataSource = new BasicDataSource();
        dataSource.setDriverClassName(driver);
        dataSource.setUrl(url);
        dataSource.setUsername(username);
        dataSource.setPassword(password);
        return dataSource;
    }
}
